#!/bin/sh

if [ "$1" == "httpd24" ] ; then
	if [ "$(rpm -qa|grep 'httpd24u-')" == "" ] ; then
		if [ "$(rpm -qa|grep 'httpd-')" == "" ] ; then
			echo
			echo "- Need select apache or proxy in 'Switch Programs'"
			echo
			exit
		else
			service httpd stop
			yum remove httpd-* mod_* -y
			yum install httpd24u httpd24u-filesystem httpd24u-tools -y
			yum install mod24u_suphp mod24u_ssl mod24u_session mod24u_ruid2 -y
			cp -f /opt/configs/apache/etc/conf/httpd24.conf /etc/httpd/conf/httpd.conf
			chkconfig httpd on

			echo
			echo "- Then, run 'sh /script/fixweb; sh /script/fixphp; sh /script/restart-web -y'"
			echo
			exit
		fi
	else
		echo
		echo "- httpd24 already installed"
		echo
		exit
	fi

	cat '' > /usr/local/lxlabs/kloxo/etc/flag/use_apache24.flg
elif [ "$1" == "httpd" ] ; then
	if [ "$(rpm -qa|grep 'httpd-')" == "" ] ; then
		if [ "$(rpm -qa|grep 'httpd24u-')" == "" ] ; then
			echo
			echo "- Need select apache or proxy in 'Switch Programs'"
			echo
			exit
		else
			service httpd stop
			yum remove httpd24u-* mod24u_* -y
			yum install httpd httpd-tools -y
			yum install mod_suphp mod_ssl mod_ruid2 mod_fastcgi mod_fcgid mod_rpaf mod_define mod_perl -y
			cp -f /opt/configs/apache/etc/conf/httpd.conf /etc/httpd/conf/httpd.conf
			chkconfig httpd on

			echo
			echo "- Then, run 'sh /script/fixweb; sh /script/fixphp; sh /script/restart-web -y'"
			echo
			exit
		fi
	else
		echo
		echo "- httpd already installed"
		echo
		exit
	fi
	
	rm -f /usr/local/lxlabs/kloxo/etc/flag/use_apache24.flg
else
	echo
	echo "- Execute: '$0 httpd' or '$0 httpd24'"
	echo
fi

